package Reeks5.VanRansbeeck.Kevin.View;

import Reeks5.VanRansbeeck.Kevin.Util.Settings;
import Reeks5.VanRansbeeck.Kevin.View.Cards.*;
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import javax.swing.*;
import javax.swing.border.LineBorder;

public class SettingsScreen extends CenteredFrame {
    JPanel panel;
    CardDrawer[] drawers;
    
    JButton[] cardlbl;
    
    final int DRAWERSIZE = 4;
    
    public SettingsScreen() {
        super(Settings.lang.getSettings(),600,200);
        panel = new JPanel(new FlowLayout());
        drawers = new CardDrawer[DRAWERSIZE];
        cardlbl = new JButton[DRAWERSIZE];
        
        drawers[0] = new CardDrawerGrimaud();
        drawers[1] = new CardDrawerKabale();
        drawers[2] = new CardDrawerMaritimes();
        drawers[3] = new CardDrawerWilhelmTell();
        
        addCards();
        
        add(panel);
        
        setVisible(true);
    }
    
    private void addCards() {
        for(int i = 0; i < DRAWERSIZE; i++) {
            JPanel kaartPanel = new JPanel(new GridLayout(0, 1));
            
            URL imageLoc = ClassLoader.getSystemResource(drawers[i].getDeckURL());
            
            System.out.println(imageLoc);
            
            cardlbl[i] = new JButton(new ImageIcon(imageLoc));
            
            // Actieve "drawer" (kaarttype) rood omlijnen
            if(Settings.cd.getDrawerName().equals(drawers[i].getDrawerName())) {
                cardlbl[i].setBorder(new LineBorder(Color.red, 2));
            }
            
            cardlbl[i].addActionListener(new ChangeCardDrawer());
            
            kaartPanel.add(cardlbl[i]);
            //kaartPanel.add(new JLabel(drawers[i].getDrawerName()));
            
            panel.add(kaartPanel);
        }
    }
    
    public class ChangeCardDrawer extends AbstractAction {

        public void actionPerformed(ActionEvent ae) {
            if(ae.getSource() == cardlbl[0]) {
                Settings.cd = new CardDrawerGrimaud();
            } else if(ae.getSource() == cardlbl[1]) {
                Settings.cd = new CardDrawerKabale();
            } else if(ae.getSource() == cardlbl[2]) {
                Settings.cd = new CardDrawerMaritimes();
            } else if(ae.getSource() == cardlbl[3]) {
                Settings.cd = new CardDrawerWilhelmTell();
            } 
            dispose();
        }
        
    }
}